<?php
/*
 *      index.php
 *      
 *      Copyright 2011 Vitaliy Rakitin <virak@ukr.net>
 *      
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<title>Словари</title>
	<meta http-equiv="content-type" content="text/html;charset=utf-8" />
	<meta name="generator" content="Geany 0.20" />
</head>
<body>
<?php
	require_once($_SERVER['DOCUMENT_ROOT']."/classes/metadata/osmetadata.php");
	
function displayform(&$tabular) {
	echo "<a href='./fields/index.php?dictionary=".$_GET["dictionary"]."&tabular=".$tabular->uuid."'>Поля (".$tabular->fields->count().")</a><br>";
	//echo "<a href='./tabulars/index.php?dictionary=".$dictionary->uuid."'>Таблицы (".$dictionary->tabulars->count().")</a><br>";
	echo "<form name='edit' action='./index.php?dictionary=".$_GET["dictionary"]."&tabular=".$tabular->uuid."' method='post'>";
	echo "<table>";
	echo "<tr><td>uuid</td><td><input type='text'  disabled='disabled' name='uuid' size='32' value='".$tabular->uuid."'></td></tr>";
	echo "<tr><td>name</td><td><input type='text' name='name' size='32' value='".$tabular->name."'></td></tr>";
	echo "</table>";
	echo "<input type='submit' name='save' value='Сохранить'>";
	echo "</form>";
}

function save(&$tabular) {
	$tabular->name = $_POST["name"];
}

	echo "<a href='../index.php?dictionary=".$_GET["dictionary"]."'><< Назад</a><br><br>";
	//echo "GET: <pre>".print_r($_GET,1)."</pre><br>";
	//echo "POST: <pre>".print_r($_POST,1)."</pre><br>";
	
	$dictionary = $metadata->dictionaries->byuuid($_GET["dictionary"]);
	if ($dictionary) {
		$tabular = $dictionary->tabulars->byuuid($_GET["tabular"]);
		if ($tabular) {
			if (array_key_exists("save",$_POST)) {
				save($tabular);
			}
		} else {
			$tabular = $dictionary->tabulars->add();
		}
		displayform($tabular);
	} else {
		echo "Словарь с uuid ".$_GET["dictionary"]." не найден!";
	}
?>
</body>
</html>
